package com.wxyzz.canteenadmin.canteencard.sale.controller;

import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.canteencard.sale.param.SaleParam;
import com.wxyzz.canteenadmin.canteencard.sale.service.SaleService;
import com.wxyzz.canteenadmin.canteencard.sale.vo.SaleVo;
import com.wxyzz.canteenadmin.vip.entity.member.Member;
import com.wxyzz.canteencommon.common.R;
import com.wxyzz.canteencommon.entity.card.sale.Sale;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author zhouhaoyu
 * @date 2024/10/11
 * @desc
 */
@RestController
@RequestMapping("/canteenCard/sale")
public class SaleController {
    @Resource
    private SaleService saleService;

    @GetMapping("/page")
    public R findAllSaleAndPage(SaleParam saleParam){
        System.out.println("saleParam = " + saleParam);
        PageInfo<SaleVo> pageInfo =  saleService.findAllSaleAndPage(saleParam);

        return R.ok(pageInfo);
    }

    @PostMapping("/del")
    public R delSaleById(Integer saleId){
        saleService.delSaleById(saleId);
        return R.ok();
    }

    /**
     * 在这个模块中调用会员表，因为雅钊没写
     */
    // 查询member返回list
        @GetMapping("/findAllMember")
    public R findAllMember(){
        List<Member> memberList = saleService.findAllMember();
        //System.out.println("memberList = " + memberList);
        return R.ok(memberList);
    }

    /**
     * 在这个模块中调用会员表，因为雅钊没写
     */
    @GetMapping("/findMemberById")
    public R findMemberById(Integer memberId){
        System.out.println("memberId = " + memberId);

        Member member = saleService.findMemberById(memberId);
        return R.ok(member);
    }

    @PostMapping("/insert")
    public R insterSale(@RequestBody Sale sale){
        saleService.insertSale(sale);
        return R.ok();
    }

}
